<template>
	<view class="beijingse">
		<view style="color:red;font-size: 20rpx;background-color: yellow;text-align: center;padding: 10rpx;">此投诉为本小程序自有投诉渠道，非微信官方投诉渠道</view>
		<view class="" style="padding-bottom: 100rpx;">
			<view class="ffffff mainpadding">
				<view class="xiahuaxian">
					<view class="strongtext xiaohei">问题类型</view>
				</view>
				<input class="margin_top" type="text" placeholder="请输入" v-model="wtlx">
			</view>
			<view class="ffffff mainpadding margin_top">
				<view class="xiahuaxian">
					<view class="strongtext xiaohei">问题或建议</view>
				</view>
				<textarea class="margin_top" placeholder="我们很期待你对我们的不足提出建议；" v-model="des"></textarea>
			</view>
			<view class="ffffff mainpadding margin_top">
				<view class="xiahuaxian">
					<view class="strongtext xiaohei">添加图片({{images_text.length}}/6)</view>
				</view>
				<view class="flexleft flex_wrap" style="width: 100%;">
					<view class="flexcenter margin_top" style="width: 16.6%;" v-for="(item,index) in images_text"
						:key="index">
						<view class="shantp dingwei ">
							<image :src="item" mode=""></image>
							<view class="shanchu" @click="deleteimg(images,images_text,index)"></view>
						</view>
					</view>
					<view class="flexcenter margin_top" style="width: 16.6%;">
						<view class="huibox" @click="uploadImg(6,images,images_text)" v-if="images_text.length!=6">
							<view class="shangctp"></view>
						</view>
					</view>
				</view>
			</view>
			<view class="ffffff mainpadding margin_top">
				<view class="xiahuaxian">
					<view class="strongtext xiaohei">联系方式</view>
				</view>
				<input class="margin_top" type="text" placeholder="请输入您的联系方式" v-model="mobile">
			</view>
			<view class="mainpadding flexleft">
				<u-radio-group v-model="type" placement="row" circle>
					<u-radio activeColor="#feb800" :customStyle="{marginRight: '30rpx'}" label="建议" name="1"></u-radio>
					<u-radio activeColor="#feb800" label="投诉" name="2"></u-radio>
				</u-radio-group>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="mainpadding ffffff gudingdb">
			<view class="bighbtn" @click="submit">提交反馈</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: "1",
				images: [],
				images_text: [],
				des: "",
				mobile: "",
				wtlx: ""
			}
		},
		onLoad(options) {
			this.type = options.id
		},
		methods: {
			submit(){
				if (this.wtlx == '') {
					httpRequest.toast("请输入问题类型!")
					return;
				}
				if (this.des == '') {
					httpRequest.toast("请输入反馈意见!")
					return;
				}
				if (this.mobile == '') {
					httpRequest.toast("请输入手机号码!")
					return;
				}
				httpRequest.request('/api/user/addFeddback', 'GET', {
					des:this.des,
					images:this.images.length?this.images.join():"",
					mobile:this.mobile,
					type:this.type,
					wtlx:this.wtlx
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg);
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			uploadImg(value, upImgs, upImgs_text) {
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			deleteimg(upImg, upImgs_text, index) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url);
					upImgs_text.push(image_item);

				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.shangctp {
		width: 26rpx;
		height: 26rpx;
		background-size: 100% 100%;
		background-image: url('@/static/image/system/shangchuantp.png');
	}

	.huibox {
		width: 90rpx;
		height: 90rpx;
		background: #F6F6F6;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
	}

	.shanchu {
		width: 32rpx;
		height: 32rpx;
		position: absolute;
		top: 0;
		right: 0;
		background-size: 100% 100%;
		background-image: url('@/static/image/system/shanchu1.png');
	}

	.shantp {
		width: 90rpx;
		height: 90rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.wexuanz {
		width: 36rpx;
		height: 36rpx;
		border-radius: 50%;
		border: 1rpx solid #999999;
	}
</style>